package com.lagou.blog.controller;

import com.github.pagehelper.PageInfo;
import com.lagou.blog.pojo.Article;
import com.lagou.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public String index(Model model, Integer pageNum) {
        PageInfo<Article> articles = articleService.selectAll(pageNum);
        List<Article> list = articles.getList();
        model.addAttribute("articles", list);
        model.addAttribute("pageNum", articles.getPageNum());
        model.addAttribute("totalPages", articles.getPages());
        return "client/index";
    }
}
